/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package statlar;

import internalAPI.QueryExecutor;
import internalAPI.impl.ExistServer;
import restAPI.RestAPI;

/**
 *
 * @author ferco
 */
public class Statlar{

    /**
     * Print usage
     */
    public static void help(){
        System.err.println("Usage: java -jar statlar.jar <path_to_eXist_collection> <listen_address>:<listen_port>");
    }


    /**
     * This is the statlarAPI main class
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        if (args.length < 2){
            help();
            return;
        }

        QueryExecutor executor = null;

        try {
            executor = new ExistServer(args[0]);
        } catch (ClassNotFoundException ex) {
            System.err.println("EXist support not found!");
            return;
        } catch (InstantiationException ex) {
            System.err.println("Failed to initiate eXist support!");
            return;
        } catch (IllegalAccessException ex) {
            System.err.println("Unable to access database!");
            return;
        }

        if (executor == null){
            System.err.println("Failed to create eXist connection!");
            return;
        }

        RestAPI api = new RestAPI();

        api.configureServer(args[1], executor);
        api.startServer(Integer.parseInt(args[1].substring(args[1].lastIndexOf(":")+1)));

        
    }
}
